/*
    jqGridPager 所有具有表格的页面  通用部分
 */

/****分页*****/
    $('#jqGrid').navGrid('#jqGridPager',
        // the buttons to appear on the toolbar of the grid
        // { edit: true, add: true, del: true, search: false, refresh: true, view: false, position: "left", cloneToTop: false },
        // Edit Dialog
        {
            // editCaption: "修改SIM卡信息",
            template: template,
            closeOnEscape: true,//Closes the popup on pressing escape key
            closeAfterEdit: true,
            reloadAfterSubmit :true,
            drag :true,
            afterSubmit: function (response, postdata) {
                if (response.responseText == "")
                {
                    $(this).jqGrid('setGridParam',
                    {
                        datatype: 'json'
                    }).trigger('reloadGrid');//Reloads the grid after edit
                    return [true, ""];
                }
                else
                {
                    $(this).jqGrid('setGridParam',
                    {
                        datatype: 'json'
                    }).trigger('reloadGrid'); //Reloads the grid after edit
                    return [false, response.responseText];//Captures and displays the response text on th Edit window
                }
            },
            editData: {
                id: function () {
                    var sel_id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
                    var value = $('#jqGrid').jqGrid('getCell',sel_id, 'id');
                    return value;
                }
            },
            errorTextFormat: function (data) {
                return 'Error: ' + data.responseText
            }
        },
        // Add Dialog
        {
            // addCaption: "添加SIM卡信息",
            closeAfterAdd: true,//添加后关闭窗口
            template: template,
            afterSubmit:function (response, postdata) {
                if (response.responseText == "")
                {
                    $(this).jqGrid('setGridParam',{
                        datatype: 'json'
                    }).trigger('reloadGrid');//Reloads the grid after Add
                    return [true, ''];
                }
                else
                {
                    $(this).jqGrid('setGridParam', {
                        datatype: 'json'
                    }).trigger('reloadGrid')//Reloads the grid after Add
                    return [false, response.responseText];
                }
            },
            errorTextFormat: function (data) {
                return 'Error: ' + data.responseText
            }
        },
        // Delete Dailog
        {
            closeOnEscape: true,    //取消后关闭窗口
            closeAfterDelete :true, //删除后关闭窗口
            reloadAfterSubmit : true, //删除后刷新页面
            afterSubmit:function (response, postdata) {
                if (response.responseText == "")
                {
                    $("#jqGrid").trigger("reloadGrid", [{current: true}]) ;
                    return [false, response.responseText];
                }
                else
                {
                    $(this).jqGrid('setGridParam', {
                        datatype: 'json'
                    }).trigger('reloadGrid');
                    return [true, response.responseText];
                }
            },
            delData: {
                EmpId: function () {
                    var sel_id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
                    var value = $('#jqGrid').jqGrid('getCell',sel_id, 'id');
                    return value;
                }
            },
            errorTextFormat: function (data) {
                return 'Error: ' + data.responseText
            }
        },
        {//SEARCH
            closeOnEscape: true,
            multipleSearch:true
        }
    );
